class Myplugin{
  constructor(options){
    this.options = options
  }
  apply(compiler){
    const hooks = compiler.hooks;
    if(hooks){
      hooks.emit.tap('myplugin',function(complication,callback){
        var str = '文件列表是:\n';
        for(let k in complication.assets){
          if(/chunk-vendors\.\w+\.js$/.test(k)){
            let str = complication.assets[k].children[0]._value;
            complication.assets[k].children[0]._value = str.replace(/\n +\* (.+)?/g,'');
          }
          str += `文件名:${k},,,大小是 ${ complication.assets[k].size()} \n\n`
        }
        complication.assets['myfile.md'] = {
          source(){
            return str
          },
          size(){
            return str.length
          }
        }
        callback&&callback()
      })
    }else{
      compiler.plugin('emit',function(complication,callback){
        var str = '文件列表是:\n';
        for(let k in complication.assets){
          if(/chunk-vendors\.\w+\.js$/.test(k)){
            let str = complication.assets[k].children[0]._value;
            complication.assets[k].children[0]._value = str.replace(/\n +\* (.+)?/g,'');
          }
          str += `文件名:${k},,,大小是 ${ complication.assets[k].size()} \n\n`
        }
        complication.assets['myfile.md'] = {
          source(){
            return str
          },
          size(){
            return str.length
          }
        }
        callback&&callback()
      })
    }
    
  }
}
module.exports = Myplugin